<?php
/**
 * Created by PhpStorm.
 * User: luzhaoyang
 * Date: 2017/8/28
 * Time: 10:24
 */

class Post extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getPosts()
    {
        $post = $this->input->post();
        if (!isset($post['sls'])||empty($post['sls'])) $this->error();
        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $this->error();
        else $limit = (int)$post['pagesize'];
        if (isset($post['page'])&&is_numeric($post['page'])) $offset = ((int)$post['page']-1)*$limit;
        else $offset = 0;
//        $post['sls']='2cAhDI';
//        $offset=0;
//        $limit=10;
        //获取海报列表
        $this->load->model('kdtsalesman_model');
        $data = $this->kdtsalesman_model->getPosts($offset,$limit);
        //生成专属海报
        $this->load->model('image_model');
        $res=array();
        foreach ($data as $row){
            $url=$this->image_model->createSlsPost($row['id'],$post['sls']);
            if ($url===false) $this->error();
            $res[]="http://wap.nldou.com".$url;
        }

        $this->success($res);
    }
}